package com.cg.controller;

import com.cg.dto.DepartmentDto;
import com.cg.dto.Result;
import com.cg.dto.ResultUtils;
import com.cg.entity.Department;
import com.cg.service.DepartmentService;
import com.cg.vo.DepartmentVo;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (Department)表控制层
 *
 * @author chengong
 * @since 2023-12-01 09:16:13
 */
@RestController
@RequestMapping("/dep")
public class DepartmentController {
    /**
     * 服务对象
     */
    @Resource
    private DepartmentService departmentService;

    /**
     * 查询部门表信息全部信息
     * @return
     */
    @PostMapping("/queryAll")
    public Result<List<Department>> queryAll() {
        List<Department> departments = departmentService.queryAll();
        return ResultUtils.returnDataSuccess(departments);
    }

    /**
     * 分页查询并根据部门名称模糊查询展示部门信息
     * @param departmentDto
     * @return
     */
    @PostMapping("/queryDepByDepName")
    public Result<Map<String,Object>> queryDepByDepName(@RequestBody DepartmentDto departmentDto){

        PageInfo<DepartmentVo> departmentPageInfo = departmentService.queryDepByDepName(departmentDto);

        Map<String,Object> objectMap = new HashMap<>();
        objectMap.put("pageInfo",departmentPageInfo);
        return ResultUtils.returnDataSuccess(objectMap);

    }


}

